<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>{{ i18n('business.inquiry.shipowner.view') }}</div>
        </div>

        <div class="admin_main_block_right">
          <div>
            <el-button icon="Back" @click="router.push({ name: 'module_business_inquiry_shipowner_list', query: { inquiry_id: dataForm.inquiry_id } })">
              {{ i18n('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-form label-width="120px" ref="formRef" :model="dataForm" :rules="dataRule">
          <el-card class="box-card" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('common.basic_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border :column="3">
                <el-descriptions-item width="200" :label="i18n('business.inquiry.order_no')" label-align="right">
                  <el-text v-if="dataForm.inquiry">
                    {{ dataForm.inquiry.order_no }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.shipowner.ship_name')" label-align="right">
                  {{ dataForm.shin_name }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('common.create_time')" label-align="right">
                  {{ dataForm.create_time }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.load_time')" label-align="right">
                  {{ dataForm.start_time }} ~ {{ dataForm.end_time }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.valid_hour')" label-align="right">
                  {{ dataForm.valid_hour }} {{ $t('common.hour') }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.valid_time')" label-align="right">
                  {{ dataForm.valid_time }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.description')" label-align="right" :span="3">
                  <el-text v-if="dataForm.inquiry">
                    {{ dataForm.inquiry.description }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.remark')" label-align="right" :span="3">
                  <el-text v-if="dataForm.inquiry">
                    {{ dataForm.inquiry.remark }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.shipowner.clause')" label-align="right">
                  {{ dataForm.clause }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.shipowner.is_offer')" label-align="right">
                  <el-text tag="b" :type="dataForm.is_offer.value == 1 ? 'primary' : 'danger'">
                    {{ dataForm.is_offer.text }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.shipowner.is_confirm')" label-align="right">
                  <el-text tag="b" :type="dataForm.is_confirm.value == 1 ? 'primary' : 'danger'">
                    {{ dataForm.is_confirm.text }}
                  </el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.inquiry.shipowner.sign_status')" label-align="right">
                  <el-text tag="b" :type="dataForm.sign_status.value == 0 ? 'info' : ((dataForm.sign_status.value == 5 || dataForm.sign_status.value == 6) ? 'danger' : (dataForm.sign_status.value == 1 ? 'success' : 'primary'))">
                    {{ dataForm.sign_status.text }}
                  </el-text>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never" v-if="dataForm.consignor">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.consignor.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <el-descriptions-item width="200" :label="i18n('organization.logo')" label-align="right">
                  <el-image class="cx-view-preview" :src="dataForm.consignor.logo">
                    <template v-slot:error>
                      <div class="image-slot">
                        <el-icon><Picture /></el-icon>
                      </div>
                    </template>
                  </el-image>
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('organization.chinese_title')" label-align="right">
                  {{ dataForm.consignor.chinese_title }}
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('organization.english_title')" label-align="right">
                  {{ dataForm.consignor.english_title }}
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('business.inquiry.consignor.member.nickname')" label-align="right">
                  <el-text v-if="dataForm.consignorMember">
                    {{ dataForm.consignorMember.chinese_nickname }}
                  </el-text>
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('business.inquiry.consignor.member.mobile')" label-align="right">
                  <el-text v-if="dataForm.consignorMember">
                    {{ dataForm.consignorMember.chinese_mobile }}
                  </el-text>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never" v-if="dataForm.transporter">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.transporter.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <el-descriptions-item width="200" :label="i18n('organization.logo')" label-align="right">
                  <el-image class="cx-view-preview" :src="dataForm.transporter.logo">
                    <template v-slot:error>
                      <div class="image-slot">
                        <el-icon><Picture /></el-icon>
                      </div>
                    </template>
                  </el-image>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('organization.chinese_title')" label-align="right">
                  {{ dataForm.transporter.chinese_title }}
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('organization.english_title')" label-align="right">
                  {{ dataForm.transporter.english_title }}
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('business.inquiry.transporter.member.nickname')" label-align="right">
                  <el-text v-if="dataForm.transporterMember">
                    {{ dataForm.transporterMember.chinese_nickname }}
                  </el-text>
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('business.inquiry.transporter.member.mobile')" label-align="right">
                  <el-text v-if="dataForm.transporterMember">
                    {{ dataForm.transporterMember.chinese_mobile }}
                  </el-text>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never" v-if="dataForm.price">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.shipowner.price.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-table :data="dataForm.price" stripe>
                <el-table-column :label="i18n('business.inquiry.shipowner.price.price_type')" width="80">
                  <template v-slot="scope">
                    <el-text v-if="scope.row.is_shipowner == 1" tag="b" type="primary">
                      {{ $t('business.inquiry.shipowner.price.is_shipowner') }}
                    </el-text>
                    <el-text v-else tag="b" type="danger">
                      {{ $t('business.inquiry.shipowner.price.is_consignor') }}
                    </el-text>
                  </template>
                </el-table-column>

                <el-table-column prop="shipowner" :label="i18n('business.inquiry.shipowner.price.source')" min-width="150">
                  <template v-slot="scope">
                    <el-text v-if="1 == scope.row.is_shipowner">
                      {{ scope.row.shipowner.chinese_name }}
                    </el-text>
                    <el-text v-else>
                      {{ scope.row.member.chinese_nickname }}
                    </el-text>
                  </template>
                </el-table-column>

                <el-table-column :label="i18n('business.inquiry.shipowner.price.is_now')" width="80">
                  <template v-slot="scope">
                    <el-text tag="b" :type="1 == scope.row.is_now.value ? 'danger' : ''">
                      {{ scope.row.is_now.text }}
                    </el-text>
                  </template>
                </el-table-column>

                <el-table-column :label="i18n('business.inquiry.shipowner.price.is_confirm')" width="80">
                  <template v-slot="scope">
                    <el-text tag="b" :type="1 == scope.row.is_confirm.value ? 'primary' : ''">
                      {{ scope.row.is_confirm.text }}
                    </el-text>
                  </template>
                </el-table-column>

                <el-table-column :label="i18n('business.inquiry.shipowner.price.clause')" width="80">
                  <template v-slot="scope">
                    {{ scope.row.clause.text }}
                  </template>
                </el-table-column>

                <el-table-column prop="money" :label="i18n('business.inquiry.shipowner.price.money')" width="100">
                </el-table-column>
              </el-table>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.harbor.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-table :data="dataForm.harbor" stripe>
                <el-table-column :label="i18n('business.inquiry.harbor.load_type')" width="80">
                  <template v-slot="scope">
                    <el-text v-if="scope.row.is_load == 1" tag="b" type="primary">
                      {{ $t('business.inquiry.harbor.is_load') }}
                    </el-text>
                    <el-text v-if="scope.row.is_unload == 1" tag="b" type="danger">
                      {{ $t('business.inquiry.harbor.is_unload') }}
                    </el-text>
                  </template>
                </el-table-column>

                <el-table-column prop="harbor_name" :label="i18n('business.inquiry.harbor.harbor_code')" min-width="150">
                </el-table-column>

                <el-table-column prop="second_harbor_name" :label="i18n('business.inquiry.harbor.second_harbor_code')" min-width="150">
                </el-table-column>

                <el-table-column prop="third_harbor_name" :label="i18n('business.inquiry.harbor.third_harbor_code')" min-width="150">
                </el-table-column>
              </el-table>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.goods.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-table :data="dataForm.goods" stripe>
                <el-table-column prop="goods_name" :label="i18n('business.inquiry.goods.goods_name')" min-width="240">
                </el-table-column>

                <el-table-column prop="goods_quantity" :label="i18n('business.inquiry.goods.goods_quantity')" width="100">
                </el-table-column>

                <el-table-column prop="goods_weight" :label="i18n('business.inquiry.goods.goods_weight')" min-width="180">
                </el-table-column>

                <el-table-column prop="goods_size" :label="i18n('business.inquiry.goods.goods_size')" min-width="180">
                </el-table-column>

                <el-table-column prop="goods_type" :label="i18n('business.inquiry.goods.goods_type')" width="120">
                </el-table-column>
              </el-table>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never" v-if="dataForm.contract.contract_url">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.contract.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border :column="3">
                <el-descriptions-item width="200" :label="i18n('business.inquiry.contract.contract_url')" label-align="right">
                  <el-link :href="dataForm.contract.contract_url" :underline="false" type="primary" target="_blank">
                    {{ $t('business.inquiry.contract.check') }}
                  </el-link>
                </el-descriptions-item>

                <el-descriptions-item width="200" :label="i18n('business.inquiry.shipowner.sign_time')" label-align="right">
                  {{ dataForm.sign_time }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.inquiry.resource.info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border :column="3">
                <el-descriptions-item v-for="(item, index) in dataForm.resource" :key="index" width="200" :label="i18n('business.inquiry.resource.title')" label-align="right">
                  <el-link :href="item.url" :underline="false" type="primary" target="_blank">
                    {{ item.filename }}
                  </el-link>
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup name="business-inquiry-shipowner-view">
  import { useBase } from "@/hooks/base/useBase"
  import { useForm } from "@/hooks/form/useForm"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/inquiry/shipowner')

  const dataForm = reactive({
    id: 0,
    shipowner_id: 0,
    inquiry_id: 0,
    shin_name: '',
    start_time: '',
    end_time: '',
    description: '',
    remark: '',
    valid_hour: '',
    valid_time: '',
    clause: '',
    is_offer: '',
    is_confirm: '',
    sign_status: '',
    sign_time: '',
    create_time: '',
    consignor: {},
    consignorMember: {},
    transporter: {},
    transporterMember: {},
    contract: {},
    inquiry: [],
    goods: [],
    harbor: [],
    price: [],
    resource: [],
  })

  const dataRule = reactive({})

  const {
    formRef
  } = useForm(model.value, dataForm)

  const init = (form) => {
    dataForm.id = query.id || 0

    nextTick(() => {
      form.value.resetFields()
      if (dataForm.id) {
        $http({
          url: $http.adornUrl(`/${model.value}/view/${dataForm.id}`),
          method: 'get',
          params: $http.adornParams({}),
        }).then(({ data }) => {
          if (data && data.status === 200) {
            dataForm.id = data.data.id
            dataForm.shipowner_id = data.data.shipowner_id
            dataForm.inquiry_id = data.data.inquiry_id
            dataForm.shin_name = data.data.shin_name
            dataForm.member = data.data.member
            dataForm.manager = data.data.manager
            dataForm.consignor = data.data.consignor
            dataForm.consignorMember = data.data.consignor_member
            dataForm.transporter = data.data.transporter
            dataForm.transporterMember = data.data.transporter_member
            dataForm.start_time = data.data.start_time
            dataForm.end_time = data.data.end_time
            dataForm.description = data.data.description
            dataForm.remark = data.data.remark
            dataForm.valid_hour = data.data.valid_hour
            dataForm.valid_time = data.data.valid_time
            dataForm.clause = data.data.clause.text
            dataForm.is_offer = data.data.is_offer
            dataForm.is_confirm = data.data.is_confirm
            dataForm.sign_status = data.data.sign_status
            dataForm.sign_time = data.data.sign_time
            dataForm.create_time = data.data.create_time
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/harbor/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_shipowner_id': dataForm.id
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.harbor = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.id) {
            $http({
              url: $http.adornUrl(`/${model.value}/price/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_id': dataForm.inquiry_id,
                'inquiry_shipowner_id': dataForm.id,
                'shipowner_id': dataForm.shipowner_id,
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.price = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.inquiry_id) {
            $http({
              url: $http.adornUrl(`/business/inquiry/contract/esign/data`),
              method: 'get',
              params: $http.adornParams({
                inquiry_id: dataForm.inquiry_id,
                inquiry_shipowner_id: dataForm.id,
                shipowner_id: dataForm.shipowner_id,
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.contract = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.inquiry_id) {
            $http({
              url: $http.adornUrl(`/business/inquiry/view/${dataForm.inquiry_id}`),
              method: 'get',
              params: $http.adornParams({}),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.inquiry = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.inquiry_id) {
            $http({
              url: $http.adornUrl(`/business/inquiry/goods/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_id': dataForm.inquiry_id
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.goods = data.data
              }
            })
          }
        }).then(() => {
          if (dataForm.inquiry_id) {
            $http({
              url: $http.adornUrl(`/business/inquiry/resource/select`),
              method: 'get',
              params: $http.adornParams({
                'inquiry_id': dataForm.inquiry_id
              }),
            }).then(({ data }) => {
              if (data && data.data && data.status === 200) {
                dataForm.resource = data.data
              }
            })
          }
        })
      }
    })
  }

  onMounted(() => {
    init(formRef)
  })
</script>

<style lang="scss" scoped>
  .cx-view-preview {
    padding: 0 5px;
    max-width: 120px;
    max-height: 120px;
    width: 100%;
    height: 120px;
  }
</style>
